import { UC } from '@/api/config/servicePort'
import { TreeNode, ResPage } from '@/api/interface'
import { App } from './interface'
import http from '@/api'

// 应用选项
export function listOption() {
  return http.get<TreeNode[]>(UC + `/app/options`, undefined, { loading: false })
}

// 应用列表
export function pageApp(query: App.Query) {
  return http.get<ResPage<App.Record>>(UC + `/app/page`, query)
}

// 检查是否存在
export function checkExist(query: App.CheckQuery) {
  return http.get<boolean>(UC + '/app/exist', query, { loading: false })
}

// 应用详情
export const getApp = (id: string) => {
  return http.get<Partial<App.Form>>(UC + `/app`, { id }, { loading: false })
}

// 新增应用
export const addApp = (form: Partial<App.Form>) => {
  return http.post(UC + `/app`, form)
}

// 修改应用
export const updateApp = (form: Partial<App.Form>) => {
  return http.put(UC + `/app`, form)
}

// 删除应用
export const removeApp = (id: string) => {
  return http.delete(UC + `/app`, { id })
}
